import { ipcRenderer } from "electron";

/**
 * 全屏
 */
export const toggleFullScreen = () => {
  ipcRenderer.send("toggle-full-screen");
};

/**
 * 最小化
 */
export const toggleMinimizedWindow = () => {
  ipcRenderer.send("toggle-minimized-window");
};

/**
 * 退出
 */
export const toggleWindowQuit = () => {
  ipcRenderer.send("toggle-window-quit");
};

/**
 * 获取根目录
 */
export const getAppPath = () => {
  return new Promise((resolve) => {
    ipcRenderer.once("get-app-path", (_, path) => {
      resolve(path);
    });
    ipcRenderer.send("get-app-path");
  });
};

/**
 * 启动本地静态文件
 */
export const handleAppStaticPath = (item: RunType) => {
  return new Promise((resolve) => {
    ipcRenderer.once("handle-static-path", (_, bool) => {
      console.log("bool", bool);
      resolve(bool);
    });
    ipcRenderer.send(
      "handle-static-path",
      `${item.source}\\${item.staticPath}`
    );
  });
};
